﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml.Serialization;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        int Total,X1;
        static MainWindow esse;
        static int Value;
        Timer timer;

        

        public MainWindow()
        {
            InitializeComponent();
            esse = this;
            //timer = new Timer(CalcPor,esse,1000,1000);
            //progress.Value = *Value;
        }

        private void Analiza()
        {
            int qtd = 0;
            StreamReader reader = new StreamReader("C:/Users/gabriel/Documents/resultado.xml");
            XmlSerializer xml = new XmlSerializer(typeof(List<Point>));
            List<Point> point = (List<Point>)xml.Deserialize(reader);
            List<Point> resultado = new List<Point>();
            reader.Dispose();


                for (int x = 0; x < point.Count; x++)
                {
                    Total = point.Count;
                    X1 = x;
                    Point ppoint = point[x];
                    qtd = 0;
                    for (int y = x+1; y < point.Count; y++)
                    {
                        if(Compara(ppoint,point[y]))
                        {
                            point.RemoveAt(y);
                            qtd++;
                        }
                    }
                    if (qtd!= 0)
                    {
                       resultado.Add(ppoint);
                    }
                }
            
            XmlSerializer xmls = new XmlSerializer(typeof(List<Resultado>));
            StreamWriter stream = new StreamWriter("C:/Users/gabriel/Documents/resultadoAnaliza.xml");
            xml.Serialize(stream, resultado);
            

        }
        private bool Compara(Point x1, Point x2)
        {
            if ((x1.Y == x2.Y) && (x1.X == x2.X)) { return true; }
            return false;
        }

        private async  void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Thread th = new Thread(Analiza);
            th.Start();
            
          
        }

        private void CalcPorcen()
        {
            
        }

        private void progress_MouseMove(object sender, MouseEventArgs e)
        {
           
        }
        private void Atualiza()
        {
            if (Total != 0)
            progress.Value = (100 * X1) / Total;
        }

        private void Window_MouseUp_1(object sender, MouseButtonEventArgs e)
        {
            Atualiza();
        }

        private void Window_MouseMove_1(object sender, MouseEventArgs e)
        {
            Atualiza();
        }

        private void Window_MouseEnter_1(object sender, MouseEventArgs e)
        {
            Atualiza();
        }
    }
}
